package com.example.administrator.officeplatform.Activity;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.baoyz.actionsheet.ActionSheet;
import com.example.administrator.officeplatform.MyApplication;
import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.adapter.PhotoAdapter;
import com.example.administrator.officeplatform.base.BaseActivity;
import com.example.administrator.officeplatform.bean.Constant;
import com.example.administrator.officeplatform.bean.Fileinfo;
import com.example.administrator.officeplatform.bean.SpinnerInfo;
import com.example.administrator.officeplatform.bean.BearDepartmentVoInfo;
import com.example.administrator.officeplatform.bean.TravelExpensesFormDetailVoInfo;
import com.example.administrator.officeplatform.bean.ReimbursementVoInfo;
import com.example.administrator.officeplatform.bean.PayeeInfo;
import com.example.administrator.officeplatform.kj.AuditorActivity;
import com.example.administrator.officeplatform.kj.BMSearchActivity;
import com.example.administrator.officeplatform.kj.ImageScaleUtil;
import com.example.administrator.officeplatform.kj.IpUtil;
import com.example.administrator.officeplatform.kj.PersonActivity;
import com.example.administrator.officeplatform.kj.WorkflowConfigActivity;
import com.example.administrator.officeplatform.utils.DateUtil;
import com.example.administrator.officeplatform.utils.JsonUtil;
import com.example.administrator.officeplatform.utils.UILImageLoader;
import com.google.gson.reflect.TypeToken;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.summerxia.dateselector.widget.DateTimeSelectorDialogBuilder;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.finalteam.galleryfinal.CoreConfig;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.ImageLoader;
import cn.finalteam.galleryfinal.ThemeConfig;
import cn.finalteam.galleryfinal.model.PhotoInfo;
import cn.finalteam.toolsfinal.StorageUtils;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.example.administrator.officeplatform.R.id.tv_money;
import static com.example.administrator.officeplatform.R.id.tv_skpeople;


public class TravelActivity extends BaseActivity implements View.OnClickListener{
    private TextView tv_upload,tv_bm,tv_dh,tv_bxr,tv_bxsj,tv_time,tv_hj,tv_addbm,
            tv_shr,tv_lc;
    private EditText et_travelp,et_level,et_reason;
    private LinearLayout layout_travel,layout_travelp,layout_travebm,layout_bc,layout_tj;
    private int index,peopleindex,bmindex;
    private TextView tv_add,tv_addpeople;
    private Context mContext;
    private List<Integer> numlist,numlistp,numlistbm;
    private DateTimeSelectorDialogBuilder dateSelectorStart , dateSelectorOver;
    private String newtime = DateUtil.getToday();
    private String yesterday = DateUtil.getYesterday();
    private RecyclerView recyclerView;
    private PhotoAdapter photoAdapter;
    private List<PhotoInfo> mPhotoList;
    private int REQUEST_CODE_CAMERA=1;
    private final int REQUEST_CODE_GALLERY = 1001;
    private String address = "http://192.168.5.14:8870/file/upload/image/reimbursement";
    private Integer startNum;
    private ProgressDialog mProgressDialog;
    /** 输入框小数的位数*/
    private static final int DECIMAL_DIGITS = 2;
    private String start = yesterday + ":00";
    private String over = newtime + ":00";
    private BigDecimal totalnum;
    private String userid="",realName="";
    private List<BearDepartmentVoInfo> ls_bm;
    private List<TravelExpensesFormDetailVoInfo> ls_detail;
    private List<PayeeInfo> ls_skr;
    private ReimbursementVoInfo travelMaininfo;
    private Button btn_jingjia,btn_bc;
    private List<SpinnerInfo> lsMap;
    private OkHttpClient mOkHttpClient= new OkHttpClient();
    private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/jpeg");
    private List<Fileinfo> ls_file;
    private Toolbar toolbar;
    private String id,nextAuditorId,departName;
    private String type;

    private int mYear, mMonth, mDay;
    final int DATE_DIALOG = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_travel);
    }

    @Override
    protected void initViews() {

        numlist = new ArrayList<>();
        numlistp = new ArrayList<>();
        numlistbm= new ArrayList<>();
        ls_bm= new ArrayList<>();
        ls_detail= new ArrayList<>();
        ls_skr= new ArrayList<>();
        lsMap=new ArrayList<>();
        ls_file=new ArrayList<>();
        toolbar = (Toolbar) findViewById(R.id.toolbar);

        tv_bm = (TextView) findViewById(R.id.tv_bm);
        tv_dh = (TextView)findViewById(R.id.tv_dh);
        tv_bxr=(TextView)findViewById(R.id.tv_bxr);
        tv_bxsj=(TextView)findViewById(R.id.tv_bxsj);
        et_travelp=(EditText) findViewById(R.id.et_travelp);
        et_level=(EditText) findViewById(R.id.et_level);
        tv_time=(TextView)findViewById(R.id.tv_time);
        et_reason=(EditText) findViewById(R.id.et_reason);
        tv_hj=(TextView)findViewById(R.id.tv_hj);
        tv_shr=(TextView)findViewById(R.id.tv_shr);
        tv_lc=(TextView)findViewById(R.id.tv_lc);
        layout_bc = (LinearLayout) findViewById(R.id.layout_bc);
        layout_tj = (LinearLayout) findViewById(R.id.layout_tj);
        layout_tj.setVisibility(View.GONE);
        btn_bc = (Button) findViewById(R.id.btn_bc);
        index = 0;
        peopleindex = 0;
        bmindex = 0;

        layout_travel = (LinearLayout) findViewById(R.id.layout_travel);
        layout_travelp = (LinearLayout) findViewById(R.id.layout_travelp);
        layout_travebm = (LinearLayout) findViewById(R.id.layout_travebm);

        tv_add = (TextView) findViewById(R.id.tv_add);
        tv_addpeople = (TextView) findViewById(R.id.tv_addpeople);
//        tv_addbm = (TextView) findViewById(R.id.tv_addbm);
        tv_upload = (TextView)findViewById(R.id.tv_upload);
        btn_jingjia = (Button)findViewById(R.id.btn_jingjia);

        initConfig();
        init();

        recyclerView=(RecyclerView)findViewById(R.id.rv_photo);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 3));// 布局管理器。
        recyclerView.setHasFixedSize(true);// 如果Item够简单，高度是确定的，打开FixSize将提高性能。
        recyclerView.setItemAnimator(new DefaultItemAnimator());//

        addView();
        addpeople();
//        addbm();

    }

    @Override
    protected void initData() {
        toolbar.setTitle("差旅费报销单");

        mContext=this;
        travelMaininfo=new ReimbursementVoInfo();

        SharedPreferences sharedPreferences = getSharedPreferences(Constant.USERINFO_KEY,
                Context.MODE_PRIVATE);
        userid=sharedPreferences.getString("userid","");
        realName=sharedPreferences.getString("realName", "");
        departName=sharedPreferences.getString("departName","");
        String id = sharedPreferences.getString("orgId","");
        travelMaininfo.setDepartmentId(id);
        travelMaininfo.setDepartmentName(departName);
        tv_bm.setText(departName);
        final Calendar ca = Calendar.getInstance();
        mYear = ca.get(Calendar.YEAR);
        mMonth = ca.get(Calendar.MONTH);
        mDay = ca.get(Calendar.DAY_OF_MONTH);

        totalnum = new BigDecimal(0);
        mPhotoList = new ArrayList<>();
        final PhotoInfo photoInfo = new PhotoInfo();
        mPhotoList.add(photoInfo);
        setRecyclerView();
        String orgId=MyApplication.getOrgId();
        if(null==orgId||orgId.length()==0){
            Toast.makeText(this, "未获取到部门Id，无法生成单号", Toast.LENGTH_SHORT).show();
        }else{
            getNumber(orgId);
        }
        tv_bxr.setText(realName);
        Time t = new Time();
        t.setToNow(); // 取得系统时间。
        int year = t.year;
        int month = t.month;
        int date = t.monthDay;
        tv_bxsj.setText(year + "-" + (month +1 ) + "-"
                + date);

//        tv_bxsj.setText(DateUtil.getTime());
//        getType();
    }

    @Override
    protected void initEvents() {
//        tv_bm.setOnClickListener(this);
        tv_add.setOnClickListener(this);
        tv_addpeople.setOnClickListener(this);
//        tv_addbm.setOnClickListener(this);
        tv_upload.setOnClickListener(this);
        tv_time.setOnClickListener(this);
        tv_shr.setOnClickListener(this);
        tv_lc.setOnClickListener(this);
        btn_jingjia.setOnClickListener(this);
        toolbar.setNavigationOnClickListener(this);
        btn_bc.setOnClickListener(this);

    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case DATE_DIALOG:
                return new DatePickerDialog(this, mdateListener, mYear, mMonth, mDay);
        }
        return null;
    }

    private DatePickerDialog.OnDateSetListener mdateListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                              int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;

            tv_time.setText(mYear + "-" + (mMonth+1));
            travelMaininfo.setAttributionDate(mYear + "-" + (mMonth+1)+"-"+mDay);
            }

    };

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_bm:
                Intent intent = new Intent();
                intent.setClass(mContext, BMSearchActivity.class);
                intent.putExtra("type","0");
                startActivityForResult(intent, 1);
                break;
            case R.id.tv_add:
                addView();
                break;
            case R.id.tv_addpeople:
                addpeople();
                break;
//            case R.id.tv_addbm:
//                addbm();
//                break;
            case R.id.tv_upload:
                if(mPhotoList.size()-1==0){
                    Toast.makeText(this, "请先拍照", Toast.LENGTH_SHORT).show();
                }else{
                    startNum=0;
                    String file = mPhotoList.get(startNum).getPhotoPath();
                    uploadPhoto(file);
                }
                break;
            case R.id.tv_time:
//                Intent intent1 = new Intent();
//                intent1.setClass(mContext, TimeActivity.class);
//                intent1.putExtra("index","0");
//                startActivityForResult(intent1, 1);
                  showDialog(DATE_DIALOG);
                break;
            case R.id.tv_shr:
                Intent intent2 = new Intent();
                intent2.setClass(mContext, AuditorActivity.class);
                intent2.putExtra("index",id);
                startActivityForResult(intent2, 1);
                break;
            case R.id.tv_lc:
                Intent intent3 = new Intent();
                intent3.setClass(mContext, WorkflowConfigActivity.class);
                intent3.putExtra("type","travelExpense");
                startActivityForResult(intent3, 1);
                break;
            case R.id.btn_jingjia:
                if(isNull(tv_shr)){
                    Toast.makeText(mContext, "请选择审核人", Toast.LENGTH_SHORT).show();
                    return;
                }
                sendExpense();
//                String json ="{\"attributionDate\":\"隔月结\",\"bearDepartmentVoList\":[{\"departmentId\":\"1080\",\"departmentName\":\"报销机构_1\",\"money\":111,\"pageNumber\":0,\"pageSize\":0}],\"enclosureNum\":\"1\",\"fileVoList\":[{\"fileName\":\"IMG201712211400_325655-1513836035787.jpg\"}],\"isrelation\":0,\"money\":\"255\",\"nextAuditor\":\"123\",\"nextAuditorId\":\"7fa7575261084baf81f135ae15245405\",\"pageNumber\":0,\"pageSize\":0,\"payeeList\":[{\"departentName\":\"报销机构_1\",\"departmentId\":\"1080\",\"money\":11,\"pageNumber\":0,\"pageSize\":0,\"payee\":\"1b7d1df7416043e5ac76bf6542d97a34\",\"payeeName\":\"12\"}],\"refundableMoeny\":0,\"reimbursementCode\":\"henfanachaojifana2017122100013\",\"reimbursementDate\":\"2017-12-21  13:59:32\",\"reimbursementType\":\"travelExpense\",\"reimbursementTypeName\":\"差旅\",\"reimbursementUser\":\"137\",\"reimbursementUserName\":\"要报销的zzp\",\"travelExpensesFormDetailVoList\":[{\"arriveAddress\":\"1\",\"arriveCityLeave\":\"1\",\"arriveTime\":\"2017-12-22 13:00\",\"otherBillNumber\":\"1\",\"otherMoney\":222,\"otherProject\":\"11\",\"pageNumber\":0,\"pageSize\":0,\"setoutAddress\":\"1\",\"setoutTime\":\"2017-12-21 13:00\",\"trafficBillNumber\":\"1\",\"trafficMoney\":11,\"travelDay\":\"3\",\"travelMoney\":22}]}";
//                sendExpense(json);

                break;
            case R.id.btn_bc:
                setExpenseData();
                break;
            default:
                finish();
                break;
        }
    }

    private void addView(){
        LayoutInflater layoutInflater = getLayoutInflater();
        View view = layoutInflater.inflate(R.layout.item_travel, null);
        view.setTag(index);
        layout_travel.addView(view);
        numlist.add(index);

        TravelExpensesFormDetailVoInfo info = new TravelExpensesFormDetailVoInfo();
        ls_detail.add(info);

        final View child = layout_travel.getChildAt(numlist.size()-1);
        final TextView tv_time = (TextView)child.findViewById(R.id.tv_sendtime);
        tv_time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DateTimeSelectorDialogBuilder  dateSelectorStart = DateTimeSelectorDialogBuilder.getInstance(layout_travel.getContext());
                    dateSelectorStart.setOnSaveListener(new DateTimeSelectorDialogBuilder.OnSaveListener() {
                        @Override
                        public void onSaveSelectedDate(String selectedDate) {
                            tv_time.setText(selectedDate);
                            start = selectedDate;
                            try {

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });

                dateSelectorStart.show();

            }
        });

        final TextView tv_endtime = (TextView)child.findViewById(R.id.tv_endtime);
        tv_endtime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DateTimeSelectorDialogBuilder  dateSelectorOver = DateTimeSelectorDialogBuilder.getInstance(layout_travel.getContext());
                    dateSelectorOver.setOnSaveListener(new DateTimeSelectorDialogBuilder.OnSaveListener() {
                        @Override
                        public void onSaveSelectedDate(String selectedDate) {
                            tv_endtime.setText(selectedDate);
                            over = selectedDate;
                            try {


                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });

                dateSelectorOver.show();

            }
        });

        final TextView tv_delete = (TextView)child.findViewById(R.id.tv_delete);
        tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num =Integer.parseInt(child.getTag().toString()) ;
                int i = numlist.indexOf(num);
                numlist.remove(i);
                ls_detail.remove(i);
                layout_travel.removeView(child);
            }
        });

        final EditText et_senddress = (EditText)child.findViewById(R.id.tv_senddress);
        final EditText et_enddress = (EditText)child.findViewById(R.id.tv_enddress);
        final EditText et_citylevel = (EditText)child.findViewById(R.id.tv_citylevel);
        final EditText et_djnumber = (EditText)child.findViewById(R.id.tv_djnumber);
        final EditText et_trackmoney = (EditText)child.findViewById(R.id.tv_trackmoney);
        final EditText et_days = (EditText)child.findViewById(R.id.tv_days);
        final EditText et_daymoney = (EditText)child.findViewById(R.id.tv_daymoney);
        final EditText et_other = (EditText)child.findViewById(R.id.tv_other);
        final EditText et_othernumber = (EditText)child.findViewById(R.id.tv_othernumber);
        final EditText et_othermoney = (EditText)child.findViewById(R.id.tv_othermoney);

        et_trackmoney.setFilters(new InputFilter[] { lengthFilter });
        et_trackmoney.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                totalnum = new BigDecimal(0);
                for(int i=0;i<numlist.size();i++){
                  final View child = layout_travel.getChildAt(i);
                  EditText et_trackmoney = (EditText)child.findViewById(R.id.tv_trackmoney);
                  String trackmoneyStr = et_trackmoney.getText().toString().trim();
                  if(isNull(trackmoneyStr)){

                  }else{
                      BigDecimal je = new BigDecimal(trackmoneyStr) ;
                      totalnum = totalnum.add(je);
                  }

                  EditText et_daymoney = (EditText)child.findViewById(R.id.tv_daymoney);
                  String daymoneyStr = et_daymoney.getText().toString().trim();
                  if(isNull(daymoneyStr)){

                  }else{
                      BigDecimal je = new BigDecimal(daymoneyStr) ;
                      totalnum = totalnum.add(je);
                  }

                  EditText et_othermoney = (EditText)child.findViewById(R.id.tv_othermoney);
                  String othermoneyStr = et_othermoney.getText().toString().trim();
                  if(isNull(othermoneyStr)){
                  }else{
                      BigDecimal je = new BigDecimal(othermoneyStr) ;
                      totalnum = totalnum.add(je);
                  }
              }
                tv_hj.setText(String.valueOf(totalnum));
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        et_daymoney.setFilters(new InputFilter[] { lengthFilter });
        et_daymoney.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                totalnum = new BigDecimal(0);
                for(int i=0;i<numlist.size();i++){
                    final View child = layout_travel.getChildAt(i);
                    EditText et_trackmoney = (EditText)child.findViewById(R.id.tv_trackmoney);
                    String trackmoneyStr = et_trackmoney.getText().toString().trim();
                    if(isNull(trackmoneyStr)){

                    }else{
                        BigDecimal je = new BigDecimal(trackmoneyStr) ;
                        totalnum = totalnum.add(je);
                    }

                    EditText et_daymoney = (EditText)child.findViewById(R.id.tv_daymoney);
                    String daymoneyStr = et_daymoney.getText().toString().trim();
                    if(isNull(daymoneyStr)){

                    }else{
                        BigDecimal je = new BigDecimal(daymoneyStr) ;
                        totalnum = totalnum.add(je);
                    }

                    EditText et_othermoney = (EditText)child.findViewById(R.id.tv_othermoney);
                    String othermoneyStr = et_othermoney.getText().toString().trim();
                    if(isNull(othermoneyStr)){
                    }else{
                        BigDecimal je = new BigDecimal(othermoneyStr) ;
                        totalnum = totalnum.add(je);
                    }
                }
                tv_hj.setText(String.valueOf(totalnum));
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        et_othermoney.setFilters(new InputFilter[] { lengthFilter });
        et_othermoney.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                totalnum = new BigDecimal(0);
                for(int i=0;i<numlist.size();i++){
                    final View child = layout_travel.getChildAt(i);
                    EditText et_trackmoney = (EditText)child.findViewById(R.id.tv_trackmoney);
                    String trackmoneyStr = et_trackmoney.getText().toString().trim();
                    if(isNull(trackmoneyStr)){

                    }else{
                        BigDecimal je = new BigDecimal(trackmoneyStr) ;
                        totalnum = totalnum.add(je);
                    }

                    EditText et_daymoney = (EditText)child.findViewById(R.id.tv_daymoney);
                    String daymoneyStr = et_daymoney.getText().toString().trim();
                    if(isNull(daymoneyStr)){

                    }else{
                        BigDecimal je = new BigDecimal(daymoneyStr) ;
                        totalnum = totalnum.add(je);
                    }

                    EditText et_othermoney = (EditText)child.findViewById(R.id.tv_othermoney);
                    String othermoneyStr = et_othermoney.getText().toString().trim();
                    if(isNull(othermoneyStr)){
                    }else{
                        BigDecimal je = new BigDecimal(othermoneyStr) ;
                        totalnum = totalnum.add(je);
                    }
                }
                tv_hj.setText(String.valueOf(totalnum));
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        index++;
    }
    private void addpeople(){
        LayoutInflater layoutInflater = getLayoutInflater();
        View view = layoutInflater.inflate(R.layout.item_payee, null);
        view.setTag(peopleindex);
        layout_travelp.addView(view);
        numlistp.add(peopleindex);

        PayeeInfo info = new PayeeInfo();
        ls_skr.add(info);

        final View child = layout_travelp.getChildAt(numlistp.size()-1);
        final TextView tv_delete = (TextView)child.findViewById(R.id.tv_delete);
        tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num =Integer.parseInt(child.getTag().toString()) ;
                int i = numlistp.indexOf(num);
                numlistp.remove(i);
                ls_skr.remove(i);
                layout_travelp.removeView(child);

            }
        });
        final TextView tv_people = (TextView)child.findViewById(tv_skpeople);
        tv_people.setTag(peopleindex);
        tv_people.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), PersonActivity.class);
                intent.putExtra("index", tv_people.getTag().toString());
                intent.putExtra("type", "0");
                startActivityForResult(intent, 1);
            }
        });
        final TextView tv_depart = (TextView)child.findViewById(R.id.tv_fybm);
        tv_depart.setTag(peopleindex);
        tv_depart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), BMSearchActivity.class);
                intent.putExtra("index", tv_depart.getTag().toString());
                intent.putExtra("type","2");
                startActivityForResult(intent, 1);
            }
        });
        final EditText et_money = (EditText)child.findViewById(tv_money);
        et_money.setFilters(new InputFilter[] { lengthFilter });

        peopleindex++;
    }
//    private void addbm(){
//        LayoutInflater layoutInflater = getLayoutInflater();
//        View view = layoutInflater.inflate(R.layout.item_travelbm, null);
//        view.setTag(bmindex);
//        layout_travebm.addView(view);
//        numlistbm.add(bmindex);
//
//        BearDepartmentVoInfo info = new BearDepartmentVoInfo();
//        ls_bm.add(info);
//
//        final View child = layout_travebm.getChildAt(numlistbm.size()-1);
//        final TextView tv_delete = (TextView)child.findViewById(R.id.tv_delete);
//        tv_delete.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                int num =Integer.parseInt(child.getTag().toString()) ;
//                int i = numlistbm.indexOf(num);
//                numlistbm.remove(i);
//                ls_bm.remove(i);
//                layout_travebm.removeView(child);
//            }
//        });
//        final TextView tv_depart = (TextView)child.findViewById(R.id.tv_bm);
//        tv_depart.setTag(bmindex);
//        tv_depart.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent();
//                intent.setClass(getApplicationContext(), BMSearchActivity.class);
//                intent.putExtra("index", tv_depart.getTag().toString());
//                intent.putExtra("type","2");
//                startActivityForResult(intent, 1);
//            }
//        });
//        final EditText et_money = (EditText)child.findViewById(tv_money);
//        et_money.setFilters(new InputFilter[] { lengthFilter });
//    }


    /**
    *页面回调方法
    *@author Wangzhiqiang
    *Created on 2017/12/19 15:14
    */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode ==1){
            String st = data.getExtras().getString("index");
            String person = data.getExtras().getString("person");
            String personid =data.getExtras().getString("personid");
            String departmentId = data.getExtras().getString("departmentId");
            String departmentName = data.getExtras().getString("departmentName");

            for (int i = 0; i < layout_travelp.getChildCount(); i++) { 
                View childAt = layout_travelp.getChildAt(i);
                String tag =  childAt.getTag().toString();
                if (tag.equals(st)){
                    View child = childAt;
                    TextView tv_1 = (TextView)child.findViewById(tv_skpeople);
                    TextView tv_depart = (TextView)child.findViewById(R.id.tv_bm);
                    tv_1.setText(person );
                    tv_depart.setText(departmentName);
                    ls_skr.get(i).setPayee(personid);
                    ls_skr.get(i).setPayeeName(person);
                    ls_skr.get(i).setDepartmentId(departmentId);
                    ls_skr.get(i).setDepartmentName(departmentName);
                }
            }
        }else if (resultCode == 2){
            String st = data.getExtras().getString("index");
            String departId = data.getExtras().getString("departId");
            tv_bm.setText(st);
            travelMaininfo.setDepartmentId(departId);
            travelMaininfo.setDepartmentName(st);
        }else if (resultCode == 3){
            String st = data.getExtras().getString("person");
            tv_time.setText(st);
            travelMaininfo.setAttributionDateName(st);
        }
        else if (resultCode == 5){
            String st = data.getExtras().getString("index");
            String name = data.getExtras().getString("name");
            String departId =data.getExtras().getString("departId");
            for (int i = 0; i < layout_travelp.getChildCount(); i++) {
                View childAt = layout_travelp.getChildAt(i);
                String tag =  childAt.getTag().toString();
                if (tag.equals(st)){
                    View child = childAt;
                    TextView tv_1 = (TextView)child.findViewById(R.id.tv_bm);
                    tv_1.setText(name);
                    ls_skr.get(i).setDepartmentName(name);
                    ls_skr.get(i).setDepartmentId(departId);
                }
            }
        }else if (resultCode == 6){
            String st = data.getExtras().getString("index");
            String name = data.getExtras().getString("name");
            String departId =data.getExtras().getString("departId");
            for (int i = 0; i < layout_travelp.getChildCount(); i++) {
                View childAt = layout_travelp.getChildAt(i);
                String tag =  childAt.getTag().toString();
                if (tag.equals(st)){
                    View child = childAt;
                    TextView tv_1 = (TextView)child.findViewById(R.id.tv_fybm);
                    tv_1.setText(name);
                    ls_skr.get(i).setBearDepartmentName(name);
                    ls_skr.get(i).setBearDepartmentId(departId);
                }
            }
        }
        else if (resultCode == 7){
            String processName = data.getExtras().getString("processName");
            String processId = data.getExtras().getString("processId");
            tv_lc.setText(processName);
            travelMaininfo.setWorkflowconfigId(processId);
        }else if (resultCode == 8){
            String name = data.getExtras().getString("name");
            nextAuditorId = data.getExtras().getString("id");
            tv_shr.setText(name);
        }
    }

    /**
     * 刷新, 这种刷新方法，只有一个Activity实例。
     */
    public void refresh() {
        finish();
        Intent intent = new Intent();
        intent.setClass(mContext, TravelActivity.class);
        startActivity(intent);
    }

    /**
     *设置照片列表和点击事件
     *@author Wangzhiqiang
     *Created on 2017/12/18 15:28
     */
    private void setRecyclerView(){
        recyclerView.setAdapter(photoAdapter = new PhotoAdapter(this,mPhotoList));
        setRecyclerViewClick();
    }
    private void setRecyclerViewClick(){
        photoAdapter.setOnRecyclerViewListener(new PhotoAdapter.OnRecyclerViewListener() {
            @Override
            public void onItemClick(final int position) {
                if(position==mPhotoList.size()-1) {
//                    GalleryFinal.openCamera(REQUEST_CODE_CAMERA, new GalleryFinal.OnHanlderResultCallback() {
//                        @Override
//                        public void onHanlderSuccess(int reqeustCode, List<PhotoInfo> resultList) {
//                            if (resultList != null) {
//                                mPhotoList.add(0, resultList.get(0));
//                                setRecyclerView();
//                            }
//                        }
//
//                        @Override
//                        public void onHanlderFailure(int requestCode, String errorMsg) {
//                            Log.e("onHanlderFailure", "");
//                        }
//                    });
                    showActionSheet();
                }
            }

            @Override
            public boolean onItemLongClick(final int position) {
                if(position==mPhotoList.size()-1){
                }else{
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                    builder.setTitle("提示");
                    builder.setMessage("确定要删除这张照片吗");
                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            mPhotoList.remove(position);
                            setRecyclerView();
                        }
                    });
                    builder.setNegativeButton("取消",null);
                    builder.show();

                }
                return false;
            }
        });
    }
    
    /**
    *拍照或从相册选择照片
    *@author Wangzhiqiang
    *Created on 2017/12/27 13:52
    */

     private void showActionSheet(){

         ActionSheet.createBuilder(mContext, getSupportFragmentManager())
                 .setCancelButtonTitle("取消")
                 .setOtherButtonTitles("打开相册", "拍照")
                 .setCancelableOnTouchOutside(true)
                 .setListener(new ActionSheet.ActionSheetListener() {
                     @Override
                     public void onDismiss(ActionSheet actionSheet, boolean isCancel) {

                     }

                     @Override
                     public void onOtherButtonClick(ActionSheet actionSheet, int index) {
                         switch (index) {
                             case 0:
                                 GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY,100, mOnHanlderResultCallback);
                                 break;
                             case 1:
                                 try {
                                     GalleryFinal.openCamera(REQUEST_CODE_CAMERA,mOnHanlderResultCallback);
                                 }catch (Exception e) {
                                     e.printStackTrace();
                                 }
                                 break;
                             default:
                                 break;
                         }
                     }
                 })
                 .show();
     }

    private GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback = new GalleryFinal.OnHanlderResultCallback() {
        @Override
        public void onHanlderSuccess(int reqeustCode, List<PhotoInfo> resultList) {
            if (resultList != null) {
                    mPhotoList.addAll(0,resultList);
                    setRecyclerView();

            }
        }

        @Override
        public void onHanlderFailure(int requestCode, String errorMsg) {
            Toast.makeText(mContext, errorMsg, Toast.LENGTH_SHORT).show();
        }
    };


    /**
    *上传图片
    *@author Wangzhiqiang
    *Created on 2017/12/18 15:31
    */
    private void uploadPhoto(String file){
        final String filename = DateUtil.getFileName();
        if(startNum==0){
            mProgressDialog = ProgressDialog.show(mContext, null, "正在上传中...");
        }
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
//        builder.addFormDataPart("reimbursement_image", filename, RequestBody.create(MEDIA_TYPE_PNG, new File(file)));
        builder.addFormDataPart("reimbursement_image", filename, RequestBody.create(MEDIA_TYPE_PNG,ImageScaleUtil.getBitmapByte(ImageScaleUtil.scaleImage(file))));

        //构建请求体
        RequestBody requestBody = builder.build();

        //构建请求
        Request request = new Request.Builder()
                .url(IpUtil.getAddress())//地址
                .post(requestBody)//添加请求体
                .build();

        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mProgressDialog.dismiss();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                mProgressDialog.dismiss();
                String str = response.body().string();
                //{"filename":"IMG201712211342_007877-1513834924333.jpg"}
                if (str.indexOf("filename") >= 0) {
                    Fileinfo fileinfo = new Fileinfo();
                    String  filename = JsonUtil.getMsg(str,"filename");
                    fileinfo.setFileUrl(filename);
                    ls_file.add(fileinfo);
                    if (startNum == mPhotoList.size() - 2) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(mContext, "图片上传成功", Toast.LENGTH_SHORT).show();
                            }
                        });
                        return;
                    } else {
                        startNum++;
                        String file = mPhotoList.get(startNum).getPhotoPath();
                        uploadPhoto(file);
                    }
                }else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "图片上传失败", Toast.LENGTH_SHORT).show();
                        }
                    });
                    ls_file.clear();
                    return;
                }
            }
        });

    }

    /**
    *照相机框架配置
    *@author Wangzhiqiang
    *Created on 2017/12/18 14:14
    */
    private void initConfig() {
        //配置主题
        //ThemeConfig.CYAN
        ThemeConfig theme = new ThemeConfig.Builder()
                .build();
        //配置功能
        FunctionConfig functionConfig = new FunctionConfig.Builder()
                .setEnableCamera(true)
                .setEnableEdit(true)
                .setEnableCrop(true)
                .setEnableRotate(true)
                .setCropSquare(true)
                .setEnablePreview(false)
                .build();

        //配置imageloader
        ImageLoader imageloader = new UILImageLoader();
        //设置核心配置信息
        CoreConfig coreConfig = new CoreConfig.Builder(getApplicationContext(), imageloader, theme)
                .setFunctionConfig(functionConfig)
                .build();
        GalleryFinal.init(coreConfig);
    }

    private void init() {
        File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext());

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
                .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
                .diskCacheExtraOptions(480, 800, null)
                .threadPoolSize(3) // default
                .threadPriority(Thread.NORM_PRIORITY - 2) // default
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCacheSize(2 * 1024 * 1024)
                .memoryCacheSizePercentage(13) // default
                .diskCache(new UnlimitedDiskCache(cacheDir)) // default
                .diskCacheSize(50 * 1024 * 1024)
                .diskCacheFileCount(100)
                .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
                .imageDownloader(new BaseImageDownloader(getApplicationContext())) // default
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                .writeDebugLogs()
                .build();
        com.nostra13.universalimageloader.core.ImageLoader.getInstance().init(config);
    }

    /**
     *  设置小数位数控制
     */
    private InputFilter lengthFilter = new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end,
                                   Spanned dest, int dstart, int dend) {
            if (dest.length() == 0 && source.equals(".")) {
                return "0.";
            }
            String dValue = dest.toString();
            String[] splitArray = dValue.split("\\.");
            if (splitArray.length > 1) {
                String dotValue = splitArray[1];
                if (dotValue.length() == DECIMAL_DIGITS) {
                    return "";
                }
            }
            return null;
        }

    };

    /**
    *获取报销单号
    *@author Wangzhiqiang
    *Created on 2017/12/20 14:21
    */
    private void getNumber(String departmentId){
//        departmentId="2346";
        OkHttpClient mOkHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/reimbursement/createNumber/"+departmentId)
                .header("cookie", MyApplication.getMsession())
                .build();
        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //{"error":"您不属于事业部下,无法生成报销单号"}
                //{"number":"henfanachaojifana2017121900004"}
                final String str = response.body().string();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(str.indexOf("error")>=0){
                            String Msg = JsonUtil.getMsg(str,"error");
                            Toast.makeText(mContext, Msg, Toast.LENGTH_SHORT).show();

                        }else if(str.indexOf("number")>=0){
                            String Msg = JsonUtil.getMsg(str,"number");
                            tv_dh.setText(Msg);
                            travelMaininfo.setReimbursementCode(Msg);
                        }else {
                            Toast.makeText(mContext, "未获取到单号", Toast.LENGTH_SHORT).show();
                        }

                    }
                });


            }
        });
    }
    
    /**
    *获取报销类型
    *@author Wangzhiqiang
    *Created on 2017/12/20 21:17
    */
    private void getType(){
        OkHttpClient mOkHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/dictionaries/showDiction/reimType")
                .header("cookie", MyApplication.getMsession())
                .build();
        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //{"error":"您不属于事业部下,无法生成报销单号"}
                //{"number":"henfanachaojifana2017121900004"}
                final String str = response.body().string();
                lsMap = JsonUtil.getPersons(str, new TypeToken<List<SpinnerInfo>>() {
                }.getType());

            }
        });
    }

    /**
     *获取报销单信息
     *@author Wangzhiqiang
     *Created on 2017/12/20 14:21
     */
    private void setExpenseData(){



        if(isNull(tv_lc)){
            Toast.makeText(mContext, "请选取流程", Toast.LENGTH_SHORT).show();
            return;
        }
     if(isNull(tv_bm)){
            Toast.makeText(mContext, "请选取部门", Toast.LENGTH_SHORT).show();
            return;
        }
        if(isNull(tv_dh)){
            Toast.makeText(mContext, "请获取单号", Toast.LENGTH_SHORT).show();
            return;
        }
        if(isNull(et_travelp)){
            Toast.makeText(mContext, "请填写出差人员", Toast.LENGTH_SHORT).show();
            return;
        }
        if(isNull(et_level)){
            Toast.makeText(mContext, "请填写职位级别", Toast.LENGTH_SHORT).show();
            return;
        }
        if(isNull(tv_time)){
            Toast.makeText(mContext, "请选择费用归属周期", Toast.LENGTH_SHORT).show();
            return;
        }
        if(isNull(et_reason)){
            Toast.makeText(mContext, "请填写出差事由", Toast.LENGTH_SHORT).show();
            return;
        }

        if(ls_file.size()==0){
            Toast.makeText(mContext, "请先上传附件", Toast.LENGTH_SHORT).show();
            return;
        }

        for (int i = 0; i < layout_travel.getChildCount(); i++) {
            View child = layout_travel.getChildAt(i);
            TextView tv_sendtime = (TextView)child.findViewById(R.id.tv_sendtime);
            EditText et_senddress = (EditText)child.findViewById(R.id.tv_senddress);
            TextView tv_endtime = (TextView)child.findViewById(R.id.tv_endtime);
            EditText et_enddress = (EditText)child.findViewById(R.id.tv_enddress);
            EditText et_citylevel = (EditText)child.findViewById(R.id.tv_citylevel);
            EditText et_djnumber = (EditText)child.findViewById(R.id.tv_djnumber);
            EditText et_trackmoney = (EditText)child.findViewById(R.id.tv_trackmoney);
            EditText et_days = (EditText)child.findViewById(R.id.tv_days);
            EditText et_daymoney = (EditText)child.findViewById(R.id.tv_daymoney);
            EditText et_other = (EditText)child.findViewById(R.id.tv_other);
            EditText et_othernumber = (EditText)child.findViewById(R.id.tv_othernumber);
            EditText et_othermoney = (EditText)child.findViewById(R.id.tv_othermoney);

            if(isNull(tv_sendtime)){
                Toast.makeText(mContext, "请选择出发时间", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(et_senddress)){
                Toast.makeText(mContext, "请填写出发地址", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(tv_endtime)){
                Toast.makeText(mContext, "请选择到达时间", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(et_enddress)){
                Toast.makeText(mContext, "请填写到达地址", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(et_citylevel)){
                Toast.makeText(mContext, "请填写到达城市等级", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(et_djnumber)){
                Toast.makeText(mContext, "请填写交通费单据张数", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(et_trackmoney)){
                Toast.makeText(mContext, "请填写交通费金额", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(et_days)){
                Toast.makeText(mContext, "请填写出差补助天数", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(et_daymoney)){
                Toast.makeText(mContext, "请填写出差金额", Toast.LENGTH_SHORT).show();
                return;
            }
            else{
                ls_detail.get(i).setSetoutTime(tv_sendtime.getText().toString());
                ls_detail.get(i).setSetoutAddress(et_senddress.getText().toString());
                ls_detail.get(i).setArriveTime(tv_endtime.getText().toString());
                ls_detail.get(i).setArriveAddress(et_enddress.getText().toString());
                ls_detail.get(i).setArriveCityLeave(et_citylevel.getText().toString());
                ls_detail.get(i).setTrafficBillNumber(et_djnumber.getText().toString());
                ls_detail.get(i).setTrafficMoney(new BigDecimal(et_trackmoney.getText().toString()));
                ls_detail.get(i).setTravelDay(et_days.getText().toString());
                ls_detail.get(i).setTravelMoney(new BigDecimal(et_daymoney.getText().toString()));
                if(!isNull(et_other)){
                  ls_detail.get(i).setOtherProject(et_other.getText().toString());
                }else{
                    ls_detail.get(i).setOtherProject("");
                }
                if(!isNull(et_othermoney)){
                ls_detail.get(i).setOtherMoney(new BigDecimal(et_othermoney.getText().toString()));
                }else{
                ls_detail.get(i).setOtherMoney(new BigDecimal(0));
                }
                if(!isNull(et_othernumber)){
                    ls_detail.get(i).setOtherBillNumber(et_othernumber.getText().toString());
                }else{
                    ls_detail.get(i).setOtherBillNumber("");
                }
            }
        }

        for (int i = 0; i < layout_travelp.getChildCount(); i++) {
            View child = layout_travelp.getChildAt(i);
            TextView tv_money = (TextView)child.findViewById(R.id.tv_money);
            TextView tv_skpeople= (TextView)child.findViewById(R.id.tv_skpeople);
            TextView tv_bm= (TextView)child.findViewById(R.id.tv_bm);
            TextView tv_fybm= (TextView)child.findViewById(R.id.tv_fybm);

            String money = tv_money.getText().toString();
            if(isNull(tv_skpeople)){
                Toast.makeText(mContext, "请完善收款人姓名", Toast.LENGTH_SHORT).show();
                return;
            }
            if(isNull(tv_money)){
                Toast.makeText(mContext, "请完善收款金额", Toast.LENGTH_SHORT).show();
                return;
            } else{
                ls_skr.get(i).setMoney(new BigDecimal(money));
            }
            if(isNull(tv_fybm)){
                Toast.makeText(mContext, "请完善费用所属部门", Toast.LENGTH_SHORT).show();
                return;
            }
            }

//        for (int i = 0; i < layout_travebm.getChildCount(); i++) {
//            View child = layout_travebm.getChildAt(i);
//            TextView tv_money = (TextView)child.findViewById(R.id.tv_money);
//            TextView tv_bm = (TextView)child.findViewById(R.id.tv_bm);
//            String money = tv_money.getText().toString();
//            if(isNull(tv_bm)){
//                Toast.makeText(mContext, "请费用承担部门信息", Toast.LENGTH_SHORT).show();
//                return;
//            }
//            if(isNull(tv_money)){
//                Toast.makeText(mContext, "请费用承担部门信息", Toast.LENGTH_SHORT).show();
//                return;
//            }else{
//                ls_bm.get(i).setMoney(new BigDecimal(money));
//            }
//        }
        BigDecimal sum = new BigDecimal(0);
        if(ls_skr.size()>0) {
            for (int i = 0; i < ls_skr.size();i++ ){
                sum = sum.add(ls_skr.get(i).getMoney());
            }
            if(totalnum.compareTo(sum)!=0){
                Toast.makeText(mContext, "收款总额与报销总额不一致", Toast.LENGTH_SHORT).show();
                return;
            }
        }


        travelMaininfo.setPayeeList(ls_skr);
        travelMaininfo.setTravelExpensesFormDetailVoList(ls_detail);
        travelMaininfo.setFileVoList(ls_file);
        travelMaininfo.setEnclosureNum(String.valueOf(ls_file.size()));
        if(!isNull(tv_hj)){
        travelMaininfo.setMoney(new BigDecimal(tv_hj.getText().toString()));
        }
        travelMaininfo.setState(2);
        travelMaininfo.setReimbursementUser(userid);
        travelMaininfo.setReimbursementUserName(realName);
        travelMaininfo.setReimbursementDate(tv_bxsj.getText().toString());

        String person = et_travelp.getText().toString();
        person = person.replace("，",",");
        person = person.replace(",",";");
        travelMaininfo.setTravelUsers(person+";");

        String level = et_level.getText().toString();
        level = level.replace("，",",");
        level = level.replace(",",";");
        travelMaininfo.setPositionLeave(level+";");

        travelMaininfo.setTravelReason(et_reason.getText().toString());
        travelMaininfo.setReimbursementType("travelExpense");
        travelMaininfo.setReimbursementTypeName("差旅");

        String json = JSON.toJSONString(travelMaininfo);
        bcdata(json);
    }

    /**
     *申请报销单保存数据请求
     *@author Wangzhiqiang
     *Created on 2017/12/21 10:21
     */
    private void bcdata(String json){
        mProgressDialog = ProgressDialog.show(mContext, null, "正在加载中...");
        mProgressDialog.setCancelable(true);
        mProgressDialog.setCanceledOnTouchOutside(false);
        mOkHttpClient = new OkHttpClient();

        RequestBody formBody =  FormBody.create(MediaType.parse("application/json;charset=UTF-8"),json);
        String s = MyApplication.getMsession();
        Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/reimbursement")
                .header("cookie", MyApplication.getMsession())
                .addHeader("Content-Type","application/json;charset=UTF-8")
                .post(formBody)
                .build();
        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mProgressDialog.dismiss();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接服务器异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                mProgressDialog.dismiss();

                final String str = response.body().string();
                //{"messageType":2,"type":"success","title":"操作信息","message":"提交成功","data":null}
                if(str.indexOf("success")>=0){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "保存成功", Toast.LENGTH_SHORT).show();
                            id = JsonUtil.getMsg(str, "data");
                            layout_tj.setVisibility(View.VISIBLE);
                            layout_bc.setVisibility(View.GONE);

                        }
                    });
                }else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "保存失败", Toast.LENGTH_SHORT).show();
                        }
                    });
                }

            }
        });
    }
    /**
     *申请报销单数据请求
     *@author Wangzhiqiang
     *Created on 2017/12/21 10:21
     */
    private void sendExpense(){
        mProgressDialog = ProgressDialog.show(mContext, null, "正在加载中...");
        mProgressDialog.setCancelable(true);
        mProgressDialog.setCanceledOnTouchOutside(false);
        mOkHttpClient = new OkHttpClient();
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("nextAuditorId", nextAuditorId);
        String json1 = JSON.toJSONString(map);
        RequestBody formBody =  FormBody.create(MediaType.parse("application/json;charset=UTF-8"),json1);
        String s = MyApplication.getMsession();
        Request request = new Request.Builder()
                .url(IpUtil.getIP()+"/reimbursement/reimbursement/submitReimbursement")
                .header("cookie", MyApplication.getMsession())
                .addHeader("Content-Type","application/json;charset=UTF-8")
                .post(formBody)
                .build();
        Call call = mOkHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                mProgressDialog.dismiss();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(mContext, "连接服务器异常", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                mProgressDialog.dismiss();

                String str = response.body().string();
                //{"messageType":2,"type":"success","title":"操作信息","message":"提交成功","data":null}
                if(str.indexOf("success")>=0){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "提交成功", Toast.LENGTH_SHORT).show();
                            finish();

                        }
                    });
                }else {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "提交失败", Toast.LENGTH_SHORT).show();
                        }
                    });
                }

            }
        });
    }
}
//[{"id":"expenseCost","text":"成本费用"},{"id":"travelExpense","text":"差旅"},{"id":"borrowing","text":"暂借款"},{"id":"rewardDeduction","text":"奖励扣款"},{"id":"adviceSettlement","text":"结算单"}]